package com.ruoyi.web.controller.base;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BasAgriculture;
import com.ruoyi.base.service.IBasAgricultureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农业污染源Controller
 * 
 * @author maliang
 * @date 2025-08-18
 */
@RestController
@RequestMapping("/base/agriculture")
public class BasAgricultureController extends BaseController
{
    @Autowired
    private IBasAgricultureService basAgricultureService;

    /**
     * 查询农业污染源列表
     */
    //@PreAuthorize("@ss.hasPermi('base:agriculture:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasAgriculture basAgriculture)
    {
        startPage();
        List<BasAgriculture> list = basAgricultureService.selectBasAgricultureList(basAgriculture);
        return getDataTable(list);
    }

    /**
     * 导出农业污染源列表
     */
    //@PreAuthorize("@ss.hasPermi('base:agriculture:export')")
    @Log(title = "农业污染源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasAgriculture basAgriculture)
    {
        List<BasAgriculture> list = basAgricultureService.selectBasAgricultureList(basAgriculture);
        ExcelUtil<BasAgriculture> util = new ExcelUtil<BasAgriculture>(BasAgriculture.class);
        util.exportExcel(response, list, "农业污染源数据");
    }

    /**
     * 获取农业污染源详细信息
     */
    //@PreAuthorize("@ss.hasPermi('base:agriculture:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(basAgricultureService.selectBasAgricultureById(id));
    }

    /**
     * 新增农业污染源
     */
    //@PreAuthorize("@ss.hasPermi('base:agriculture:add')")
    @Log(title = "农业污染源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasAgriculture basAgriculture)
    {
        return toAjax(basAgricultureService.insertBasAgriculture(basAgriculture));
    }

    /**
     * 修改农业污染源
     */
    //@PreAuthorize("@ss.hasPermi('base:agriculture:edit')")
    @Log(title = "农业污染源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasAgriculture basAgriculture)
    {
        return toAjax(basAgricultureService.updateBasAgriculture(basAgriculture));
    }

    /**
     * 删除农业污染源
     */
    //@PreAuthorize("@ss.hasPermi('base:agriculture:remove')")
    @Log(title = "农业污染源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(basAgricultureService.deleteBasAgricultureByIds(ids));
    }
}
